<template>
	<view>
		<tui-modal :show="modal" maskClosable="true" custom padding="20rpx 32rpx">
			<view class="tui-modal-custom flex flex-col align-center">
				<tui-icon name="close-fill" color="#999" class="tui-icon-close-fill" :size="25" @click="closePop">
				</tui-icon>
				<view class="font-14 mg-b-10">{{topicVo.title}}</view>

				<div class="pd-t-10 flex align-center">
					<!-- <div class="font-14 label">{{ topicVo.title||'' }}：</div> -->
					<view class="font-12 sublabel">{{topicVo.subtitle}}</view>
				</div>
				<image class="img pd-t-10" :src="topicVo.itemPicUrl"></image>
				<view class="font-14 tui-btn-box mg-t-20">
					<tui-button height="72rpx" width="142rpx" :size="28" type="warning" shape="circle"
						@click="goDetail">去看看</tui-button>
					<div class="mg-l-10"></div>
				</view>
			</view>
		</tui-modal>
	</view>
</template>

<script>
	const util = require("@/utils/util.js");
	const app = getApp();
	export default {
		props: {
			userId: {
				type: Boolean,
				default: false
			},
		},
		data() {
			return {
				topicVo: {},
				modal: false,
			}
		},
		watch: {
			userId(val) {
				this.getTopcAct()
			}
		},
		created() {
			this.getTopcAct()
		},
		methods: {
			closePop: function(e) {
				this.modal = false
			},
			getTopcAct: function() {
				var that = this;
				uni.login({
					success: function(r) {
						let code = r.code;
						util.request('topic/popTopic', {
							userId: uni.getStorageSync('userId'),
							code: code
						}).then(function(res) {
							if (res.code === 0) {
								if (res.data && res.data.id) {
									that.topicVo = res.data
									that.modal = true
									that.saveTopcActLog()
								}
							}
						});
					}
				})
			},
			saveTopcActLog: function() {
				var that = this;
				uni.login({
					success: function(r) {
						let code = r.code;
						util.request('topic/savePopupLog', {
							userId: uni.getStorageSync('userId'),
							code: code,
							topicId: that.topicVo.id
						});
					}
				})
			},
			goDetail() {
				var url = this.topicVo.link;
				if (this.topicVo.linkType == '0') {
					url = "/pages/shopping/couponCenter/couponCenter?couponId=" + this.topicVo.couponId
				} else if (this.topicVo.linkType == '1') {
					url = "/pages/goods/goods?id=" + this.topicVo.goodsId
				}
				console.log('url', url);
				this.modal = false
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.img {
		width: 540rpx;
		border-radius: 40rpx;
	}

	.tui-icon-close-fill {
		position: absolute;
		top: 20rpx;
		right: 30rpx;
	}
</style>
